package com.test.javase;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/17
 *4.提取字符串中的“-3.14good87nice19bye”的数值(数值包括正负数、整数和小数在内)并求和
 */
public class SumNumbers{
    public static void main(String[] args) {
        String str = "-3.14good87nice19bye";
        Pattern p = Pattern.compile("-?\\d+(\\.\\d+)?");
        Matcher m = p.matcher(str);
        double sum = 0;
        while (m.find()) {
            sum += Double.parseDouble(m.group());
        }
        System.out.println(sum);
    }
}
